package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.ArticleListBean;
import com.itboye.jinpuyiyuan.utils.sputil.Const;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/11 0011.
 */

public class HealthConsultationAdapter extends BaseAdapter {
    private ArrayList<ArticleListBean> list;
    private Context context;
    private LayoutInflater inflater;
    public  HealthConsultationAdapter(Context context,ArrayList<ArticleListBean> list){

        this.list=list;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;
        if (convertView==null){
            myHolder=new MyHolder();
            convertView=inflater.inflate(R.layout.item_healthconsultationlist,parent,false);
            myHolder.effectTv=convertView.findViewById(R.id.effectTv);
            myHolder.praiseNumTv=convertView.findViewById(R.id.praiseNumTv);
            myHolder.foodImg=convertView.findViewById(R.id.foodImg);
            convertView.setTag(myHolder);
        }else {
            myHolder= (MyHolder) convertView.getTag();
        }

        myHolder.effectTv.setText(list.get(position).getTitle());
        myHolder.praiseNumTv.setText(list.get(position).getLikes());

        Glide.with(context).load(Const.DoctorImg+list.get(position).getId()).into(myHolder.foodImg);
        return convertView;
    }

    public void addData( ArrayList<ArticleListBean> list){
        this.list=list;
        this.notifyDataSetChanged();
    }
    class MyHolder {

        TextView effectTv,praiseNumTv;
        ImageView foodImg;

    }
}
